# -*- coding: UTF-8 -*-
import concurrent.futures
from lj_tool import tool_cache, tool_sys


def lj_thread_run(func):
    def wrapper(*args, **kwargs):
        def t_func():
            func(*args, **kwargs)
        run(t_func)
    return wrapper


@tool_cache.lj_wrapper_cache("tool_thread_init_thread_pool", tool_cache.max_expiration_seconds)
def init_thread_pool():
    # 创建一个大小为 2 的线程池
    print(f"LJ - 线程池初始化...")
    return concurrent.futures.ThreadPoolExecutor(max_workers=100)


def run(fun):
    init_thread_pool().submit(fun)


def close():
    print(f"LJ - 线程池退出...")
    init_thread_pool().shutdown(wait=False)


tool_sys.exit_listen(close)
